package com.loong.life.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.param.BaseIdParam;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonValidate;
import com.loong.life.common.backend.param.ChargeIdAndOrderNumParam;
import com.loong.life.common.backend.param.PhoneChargeQueryParam;
import com.loong.life.handler.PhoneChargeHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Description: 处理后台有关手机充值请求的controller
 * @Author: 刘群
 * @Date: 2020/11/26 16:37
 */
@RestController
@RequestMapping("manage/life/phoneCharge")
public class PhoneChargeController extends BaseBackendController {

    @Resource
    private PhoneChargeHandler phoneChargeHandler;

    /**
     * 根据id查找手机充值记录
     * @param param 充值记录id
     * @return 响应的结果
     */
    @PostMapping("findById")
    public Result findPhoneChargeRecordById(@Validated({CommonValidate.class})BaseIdParam param){
        return handlerExecutor.execute(() -> phoneChargeHandler.findPhoneChargeRecordById(param.getId()));
    }

    /**
     * 分页查询手机充值记录
     * @param param  查询条件
     * @return 响应的结果
     */
    @PostMapping("pageQuery/chargeRecordList")
    public Result pageQueryPhoneChargeRecord(PhoneChargeQueryParam param){
        return handlerExecutor.execute(() -> phoneChargeHandler.pageQueryPhoneChargeRecord(param));
    }

    /**
     * 更新手机充值状态
     * @param param 充值记录id和订单编号封装的参数
     * @return 响应的结果
     */
    @PostMapping("updateStatus")
    public Result updatePhoneChargeStatus(@Validated({CommonValidate.class}) ChargeIdAndOrderNumParam param){
        return handlerExecutor.execute(() -> phoneChargeHandler.updatePhoneChargeStatus(param));
    }

    /**
     * 查询应用在代理商中的余额
     * @return 响应的结果
     */
    @PostMapping("findAccountBalance")
    public Result findAccountBalanceInAgent(@RequestParam("date")Date date){
        return handlerExecutor.execute(() -> phoneChargeHandler.findAccountBalanceInAgent(date));
    }

}
